using Senparc.Weixin.Entities;
using Senparc.Weixin.HttpUtility;
using Senparc.Weixin.Open.CommonAPIs;
using System;
using System.Linq;
namespace Senparc.Weixin.Open.QRConnect
{
	public static class QRConnectAPI
	{
		public static string GetQRConnectUrl(string appId, string redirectUrl, string state, OAuthScope[] scopes, string responseType = "code")
		{
			string arg_56_0 = "https://open.weixin.qq.com/connect/qrconnect?appid={0}&redirect_uri={1}&response_type={2}&scope={3}&state={4}#wechat_redirect";
			object[] array = new object[5];
			array[0] = appId;
			array[1] = redirectUrl.UrlEncode();
			array[2] = responseType;
			array[3] = string.Join(",", 
				from z in scopes
				select z.ToString());
			array[4] = state;
			return string.Format(arg_56_0, array);
		}
		public static QRConnectAccessTokenResult GetAccessToken(string appId, string appSecret, string code, string grantType = "authorization_code")
		{
			string urlFormat = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type={3}", new object[]
			{
				appId,
				appSecret,
				code,
				grantType
			});
			return CommonJsonSend.Send<QRConnectAccessTokenResult>(null, urlFormat, null, CommonJsonSendType.GET, 10000);
		}
		public static RefreshAccessTokenResult RefreshToken(string appId, string refreshToken, string grantType = "refresh_token")
		{
			string urlFormat = string.Format("https://api.weixin.qq.com/sns/oauth2/refresh_token?appid={0}&grant_type={1}&refresh_token={2}", appId, grantType, refreshToken);
			return CommonJsonSend.Send<RefreshAccessTokenResult>(null, urlFormat, null, CommonJsonSendType.GET, 10000);
		}
		public static QRConnectUserInfo GetUserInfo(string accessToken, string openId)
		{
			string urlFormat = string.Format("https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}", accessToken, openId);
			return CommonJsonSend.Send<QRConnectUserInfo>(null, urlFormat, null, CommonJsonSendType.GET, 10000);
		}
		public static WxJsonResult Auth(string accessToken, string openId)
		{
			string urlFormat = string.Format("https://api.weixin.qq.com/sns/auth?access_token={0}&openid={1}", accessToken, openId);
			return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, null, CommonJsonSendType.GET, 10000);
		}
	}
}
